<template>
  <page-wrap back dark hide-tab title="切换身份" bg-color="transparent">
    <view class="character" :style="'padding-top:' + navHeight + 'px;'">
      <view class="character-img">
        <image :src="charList[activeChar].img"></image>
      </view>
      <view class="character-tips">您目前是<text>{{ charList[activeChar].name }}</text>身份</view>
      <u-button type="primary" @click="handleCharacter"> {{ charList[activeChar].actionName }} </u-button>
    </view>
  </page-wrap>
</template>

<script>
import IMEventHandler from "@/utils/im";
import companyMixin from "@/mixins/companyStatus";
import ShareMixin from "@/mixins/share";

export default {
  mixins: [companyMixin, ShareMixin],
  data() {
    return {
      navHeight: 0,
      selectedItem: "",
      active: "person",
      charList: [
        {
          name: "求职",
          actionName: "我要招聘",
          value: 0,
          img: this.$imgBase + "character/bg-person.png?v=1",
          url: "/pages/companyCenter/index",
          data: "companyTabs",
          type: "company",
        },
        {
          name: "招聘",
          actionName: "我要求职",
          value: 1,
          img: this.$imgBase + "character/bg-company.png?v=1",
          url: "/pages/userCenter/index",
          data: "personTabs",
          type: "person",
        },
        {
          name: "求职",
          actionName: "我是职途顾问",
          value: 2,
          img: this.$imgBase + "character/bg-person.png?v=1",
          url: "/pagesSub/careerGrow/consultantCenter/index",
          data: "consultantTabs",
          type: "consultant",
        },
      ],
    };
  },
  computed: {
    activeChar() {
      return this.active === "consultant"
        ? 2
        : this.active === "company"
        ? 0
        : 1;
    },
  },
  onLoad: function (option) {
    // active 是将要激活的端
    this.active = option.active || "person";
  },
  created() {
    // #ifdef MP-WEIXIN
    this.navHeight = getApp().globalData.navHeight;
    // #endif
  },
  methods: {
    handleCharacter() {
      this.selectedItem = this.charList[this.activeChar];
      // getApp().globalData.tabBarList = getApp().globalData[this.charList[this.activeChar].data];
      // getApp().globalData.loginStatus = this.charList[this.activeChar].type;
      // uni.setStorageSync("login-status", this.charList[this.activeChar].type);
      if (this.selectedItem.type == "person") {
        this.setIdentityData();
        getApp().globalData.conversationList = [];
        uni.reLaunch({
          url: getApp().globalData.tabBarList[0].pagePath,
        });
      } else if (this.selectedItem.type == "consultant") {
        this.setIdentityData();
        getApp().globalData.conversationList = [];
        uni.reLaunch({
          url: getApp().globalData.tabBarList[0].pagePath,
        });
      } else {
        // this.checkCompanyStatus(); // from companyMixin

        // this.getPersonBindCompanyStatus(); // from companyMixin
        this.handlePass(); // from companyMixin
      }
    },
    setIdentityData() {
      getApp().globalData.tabBarList =
        getApp().globalData[this.selectedItem.data];
      getApp().globalData.loginStatus = this.selectedItem.type;
      uni.setStorageSync("login-status", this.selectedItem.type);
      getApp().globalData.msgUnreadCnt = 0;
      getApp().globalData.tim && getApp().globalData.tim.logout();
      uni.getStorageSync("company-id") && new IMEventHandler();
    },
  },
};
</script>

<style lang="scss">
$img-base-character: $img-base + "character/";
.character {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  height: 1rpx;
  font-size: $uni-font-size-lg;
  color: $uni-text-color-222;
  background: $uni-bg-color;
  box-sizing: border-box;
  .character-img {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    image {
      width: 750rpx;
      height: 482rpx;
    }
  }
  .character-tips {
    margin-top: 32rpx;
    text-align: center;
    text-shadow: 0 0 0;
    letter-spacing: 1rpx;
    text {
      color: $u-type-primary;
    }
  }
  ::v-deep button {
    margin: 54rpx 32rpx 80rpx;
    padding: 22rpx;
    line-height: normal;
    font-size: $uni-font-size-lg;
    // background: $uni-text-color-error;
    border-radius: 24rpx;
  }
}
</style>
